package com.example.repository;

import com.example.domain.Student;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface StudentRepository extends PagingAndSortingRepository<Student, Integer> {
    Optional<Student> findByAccountAndPassword(String account, String password);
    
    Page<Student> findAllByType(int type, Pageable pageable);
    
    Page<Student> findAllByClazz_Id(int clazzid, Pageable pageable);
    
    // Page<Student> findAllByClazz_Grade_Id(int gradeid, Pageable pageable);
    @Query(value = "select max(account) from `t_student` where clazz_id = :id ", nativeQuery = true)
    long findMaxAccount(@Param(value = "id") int id);
    
    void deleteByIdIn(int[] ids);
    
    void deleteAllByClazz_IdIn(Iterable<Integer> clazzids);
    
    
    
}
